import pubsub from 'pubsub-js'

function Top() {
    const handleClick = () => {

        // 准备要发送的数据对象
        // let data = 'Hello from Top'
        // let data = {msg: 'Hello from Top'}
        let data = { 
            arr : [
                {id : 1,name: 'zhang'},
                {id : 2,name: 'xu'},
                {id : 3,name: 'wang'}
            ]
        }
        pubsub.publish('MY_TOPIC',data) // 发布数据到名为MY_TOPIC的主题中
    }
    return (
        <div className="Top">
            消息发布
            <button onClick={handleClick}>Send Message To Buttom</button>   {/*点击按钮触发数据发布*/}
        </div>
    );
}

export default Top
